const express = require('express')
const app = express()
const dayjs = require('dayjs')
const fs = require('fs')
app.get('/', (req, res) => {
    const newName = req.query.name.replace('a', 'b')
    res.send(newName)
})
function errHandle(err, req, res, next) {
    console.log(err.stack);
    const obj = {
        date: dayjs().format('YYYY-MM-DD HH:mm:ss'),
        stack: err.stack,
        url: req.url,
        method: req.method
    }
    fs.appendFileSync('./log/error', JSON.stringify(obj))
    res.send('后端出错了,请稍后重试')
}

app.use(errHandle)


app.listen(8000, () => { console.log('8000开启成功'); })